#include "oledtask.h"

void oledtask(void)
{
    ////////////////载波频率输入定义变量///////////////////////////////////////////////////↓
    num_cal num_cal_tmp;          //数值调整结构全局变量
    unsigned int cursor_position; //输入数据光标的位置
    ////////////////符号率输入定义变量/////////////////////////////////////////////////////↓
    num_cal num_cal_sign;
    ///////////////信息速率输入定义变量////////////////////////////////////////////////////↓
    num_cal num_cal_information;
    unsigned char str[10]; //sprintf显示储存位置
    int k = 1;             //控制第一层循环
    int j = 1;             //控制DEC中每项循环
                           //	int z=1;                                                          			 							             //控制第一层中“载波频率”选项的第二层循环

    int modul = 0;                                                                     //控制调制方式数组的下标
    const char *Modulation_Mode[] = {"BPSK", "QPSK", "OQPSK", "8PSK", "8QAM", "16QAM"}; //调制方式
	const int Modulation_Mode1[6] = {1,2,2,3,3,4};
	int modul1 = Modulation_Mode1[modul];
	
    int decmo = 0;                                                            //控制译码方式数组的下标
    const char *Decoded_Mode[] = {"OFF", "VIT", "TPC", "TCM", "LDPC", "SEQ"}; //译码方式

    int scram = 0;                                                      //控制扰码数组的下标
    const char *Scramble[] = {"OFF", "V35", "IBS15", "TPC11", "TPC12"}; //扰码

    int frame = 0;                                                                          //控制帧结构数组的下标
    const char *Frame_Structure[] = { "IBS", "DROP", "IDR", "EDMAC", "DVB","ESC++", "EDMAC2","D&I++","COM"}; // 帧结构

    int cde = 0;                                                                                      //编码码率的下标
    const char *code[] = {"1/1", "1/2", "2/3", "3/4", "5/6", "7/8", "15/16", "21/44","5/16","0.49", "0.79", "0.95"}; //编码码率
	const double code1[12] = {1.0,0.5,0.66666666,0.75,0.83333333,0.875,0.9375,0.47727272,0.3125,0.49,0.79,0.95};
	double cde1 = code1[cde];
	
    int itwdp = 0;                                                //RS交织深度的下标
    const char *RS_Interweave_Depth[] = {"NONE", "4", "8", "12"}; //RS交织深度

    int demo = 0;                                                                                                           //RS译码模式下标
    const char *RS_Decoding_Mode[] = {"OFF", "(126,112)", "(219,201)", "(194,178)", "(204,188)", "(255,223)", "(160,146)"}; //RS译码模式
	const double RS_Decoding_Mode1[7] = {1.0, 0.5, 0.91780822, 0.91752577, 0.92156862, 0.87450980, 0.9125};
    double demo1 = RS_Decoding_Mode1[demo];
	 
	int cep = 0;                            //倒谱的下标
    const char *cepstrum[] = {"YES", "NO"}; //倒谱

    // int dif = 0;                              //差分的下标
    // const char *difference[] = {"YES", "NO"}; //差分
	
	int IB = 0;
	const char *IBS[] = {  "00064.000","00128.000","00192.000","00256.000","00320.000","00384.000","00448.000",
							 "00512.000","00576.000","00640.000","00704.000","00768.000","00832.000","00896.000",
							 "00960.000","01024.000","01088.000","01152.000","01216.000","01280.000","01344.000",
							 "01408.000","01472.000","01536.000","01544.000","01600.000","01664.000","01728.000",
							 "01792.000","01856.000","01920.000","01984.000","02048.000"};
	int idr = 0;
	const char *IDR[] = {"01544.000","02048.000","06312.000","08448.000"};
	
    Key_GPIO_Config();  //按键初始化
    OLED_Init();        //初始化OLED
    GBZK_GPIO_Config(); //初始化字库

    num_cal_tmp.num_temp = 123456789;
    num_cal_tmp.xb = 0;
    num_cal_sign.num_temp = 12345678;
    num_cal_sign.xb = 0;
    num_cal_information.num_temp = 12345678;
    num_cal_information.xb = 0;
    while (1)
    {
		
			
        Display_Asc_String('4', 50, 36, "SYMBOL");
        Display_Asc_String('4', 98, 32, ":");
        Display_Asc_String('4', 180, 36, "KBd");
		//////////////不同帧结构下，开机显示不同的符号率//////////////////

			if(frame==0)
				num_cal_sign.num_temp = atof(IBS[IB])*1000/ cde1 / modul1 / demo1*16/15;                //IBS
			else if (frame == 1)
				num_cal_sign.num_temp = atof(IBS[IB])*1000/ cde1 / modul1 / demo1/965*1024;			//DROP	
			else if(frame == 2)                                               
				num_cal_sign.num_temp = atof(IDR[idr])*1000/ cde1 / modul1 / demo1;                  
			else if(frame == 3)
				num_cal_sign.num_temp = num_cal_information.num_temp / cde1 / modul1 / FRAMERATE_EDMAC(num_cal_information.num_temp,cde,modul);
			else if(frame == 4||frame == 8)
				num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/demo1; 
			else if (frame == 5)
				num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/FRAMERATE_ESC(num_cal_information.num_temp);
			else if (frame == 6)
				num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/60*61; 
			else if (frame == 7)
				num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/45*46; 
			
			num_cal_sign.tmp_bit[8] = num_cal_sign.num_temp % 10; // 符号率
			num_cal_sign.tmp_bit[7] = (num_cal_sign.num_temp % 100) / 10;
			num_cal_sign.tmp_bit[6] = (num_cal_sign.num_temp % 1000) / 100;
			num_cal_sign.tmp_bit[4] = (num_cal_sign.num_temp % 10000) / 1000;
			num_cal_sign.tmp_bit[3] = (num_cal_sign.num_temp % 100000) / 10000;
			num_cal_sign.tmp_bit[2] = (num_cal_sign.num_temp % 1000000) / 100000;
			num_cal_sign.tmp_bit[1] = (num_cal_sign.num_temp % 10000000) / 1000000;
			num_cal_sign.tmp_bit[0] = (num_cal_sign.num_temp % 100000000) / 10000000;
			
			sprintf((char *)str, "%d%d%d%d%d.%d%d%d", //显示符号率
			num_cal_sign.tmp_bit[0],
			num_cal_sign.tmp_bit[1],
			num_cal_sign.tmp_bit[2],
			num_cal_sign.tmp_bit[3],
			num_cal_sign.tmp_bit[4],
			num_cal_sign.tmp_bit[6],
			num_cal_sign.tmp_bit[7],
			num_cal_sign.tmp_bit[8]);
			Display_Asc_String('4', 104, 36, str);
			
	
        /////////符号率同步关联，以下步骤不可缺
        //◤*************************************************************◥
        // num_cal_information.num_temp =
        // 	num_cal_information.tmp_bit[0] * 10000000 +
        // 	num_cal_information.tmp_bit[1] * 1000000 +
        // 	num_cal_information.tmp_bit[2] * 100000 +
        // 	num_cal_information.tmp_bit[3] * 10000 +
        // 	num_cal_information.tmp_bit[4] * 1000 +
        // 	num_cal_information.tmp_bit[6] * 100 +
        // 	num_cal_information.tmp_bit[7] * 10 +
        // 	num_cal_information.tmp_bit[8];
//		if(frame != 0)
//		{
//        num_cal_sign.num_temp = num_cal_information.num_temp / cde1 / modul1 / demo1/15*16; //关联式

//        num_cal_sign.tmp_bit[8] = num_cal_sign.num_temp % 10; // 符号率数值取位到数组
//        num_cal_sign.tmp_bit[7] = (num_cal_sign.num_temp % 100) / 10;
//        num_cal_sign.tmp_bit[6] = (num_cal_sign.num_temp % 1000) / 100;
//        num_cal_sign.tmp_bit[4] = (num_cal_sign.num_temp % 10000) / 1000;
//        num_cal_sign.tmp_bit[3] = (num_cal_sign.num_temp % 100000) / 10000;
//        num_cal_sign.tmp_bit[2] = (num_cal_sign.num_temp % 1000000) / 100000;
//        num_cal_sign.tmp_bit[1] = (num_cal_sign.num_temp % 10000000) / 1000000;
//        num_cal_sign.tmp_bit[0] = (num_cal_sign.num_temp % 100000000) / 10000000;

//        sprintf((char *)str, "%d%d%d%d%d.%d%d%d", //显示符号率
//                num_cal_sign.tmp_bit[0],
//                num_cal_sign.tmp_bit[1],
//                num_cal_sign.tmp_bit[2],
//                num_cal_sign.tmp_bit[3],
//                num_cal_sign.tmp_bit[4],
//                num_cal_sign.tmp_bit[6],
//                num_cal_sign.tmp_bit[7],
//                num_cal_sign.tmp_bit[8]);
//        Display_Asc_String('4', 104, 36, str);
//		}
        //◣ *************************************************************◢


        if (key_right) //右移按键
        {
            if (k < 6)
                k++;
            else
                k = 1;
        }
        if (key_left) // 左移按键
        {
            if (k > 1)
                k--;
            else
                k = 6;
        }

        switch (k)
        {
        case 1:
            //////////////////////////////////IF"///////////////////////////////////
            Display_Asc_String('4', 8, 8, "IF FRAME MODE DATA DEC MONITER");
            Display_Asc_String('4', 8, 20, "-                             ");
            /////////////////////////进入第二层/////////////////////////////////////
            if (key_enter)
            {
                Fill_RAM(0x00);
                //				num_cal_tmp.tmp_bit[10] =  num_cal_tmp.num_temp%10;                        // 将数值每一个位储存在数组的每一位里
                //				num_cal_tmp.tmp_bit[9] = (num_cal_tmp.num_temp%100)/10;
                //				num_cal_tmp.tmp_bit[8] = (num_cal_tmp.num_temp%1000)/100;
                num_cal_tmp.tmp_bit[6] = ((num_cal_tmp.num_temp / 1000) % 10) / 1; //除以1000的目的是因为只显示三位小数
                num_cal_tmp.tmp_bit[5] = ((num_cal_tmp.num_temp / 1000) % 100) / 10;
                num_cal_tmp.tmp_bit[4] = ((num_cal_tmp.num_temp / 1000) % 1000) / 100;
                num_cal_tmp.tmp_bit[2] = ((num_cal_tmp.num_temp / 1000) % 10000) / 1000;
                num_cal_tmp.tmp_bit[1] = ((num_cal_tmp.num_temp / 1000) % 100000) / 10000;
                num_cal_tmp.tmp_bit[0] = ((num_cal_tmp.num_temp / 1000) % 1000000) / 100000;

                Display_Asc_String('4', 8, 8, "FREQ");
                Display_Asc_String('4', 40, 5, ":");
                Display_Asc_String('4', 102, 8, "MHz");
                Display_Asc_String('4', 136, 8, "CEPSTRUM");
                cursor_position = 47 + num_cal_tmp.xb * 8;
                Display_Asc_String('2', cursor_position, 22, "-");
                Display_Asc_String('4', 204, 5, ":");
                sprintf((char *)str, "%s", cepstrum[cep]);
                Display_Asc_String('4', 214, 8, str);
                Display_GBasc_String('2', 16, 32, "(52,000,000");
                //Display_GB2312_String('2', 106, 30, "～");
                Display_Asc_String('2', 106, 30, "~");
                Display_GBasc_String('2', 120, 32, "176,000,000)");
                Display_Asc_String('4', 216, 31, "HZ");

                sprintf((char *)str, "%d%d%d.%d%d%d",
                        num_cal_tmp.tmp_bit[0],
                        num_cal_tmp.tmp_bit[1],
                        num_cal_tmp.tmp_bit[2],
                        num_cal_tmp.tmp_bit[4],
                        num_cal_tmp.tmp_bit[5],
                        num_cal_tmp.tmp_bit[6]);
                Display_Asc_String('4', 47, 8, str);
                ///////////////////////////////////////////////////////////////////////
                while (1)
                {
                    if (key_right) ////右移
                    {
                        Display_Asc_String('2', cursor_position, 22, " "); //消除上一次光标的位置痕迹/
                        num_cal_tmp.xb++;
                        if (num_cal_tmp.xb > 7)
                            num_cal_tmp.xb = 0;
                        if (num_cal_tmp.xb == 3)
                            num_cal_tmp.xb++;
                        if (num_cal_tmp.xb == 7)
                        {
                            num_cal_tmp.xb = num_cal_tmp.xb + 14;
                        }
                        cursor_position = 47 + num_cal_tmp.xb * 8;
                        Display_Asc_String('2', cursor_position, 22, "-");
                        sprintf((char *)str, "%d%d%d.%d%d%d",
                                num_cal_tmp.tmp_bit[0],
                                num_cal_tmp.tmp_bit[1],
                                num_cal_tmp.tmp_bit[2],
                                num_cal_tmp.tmp_bit[4],
                                num_cal_tmp.tmp_bit[5],
                                num_cal_tmp.tmp_bit[6]);
                        Display_Asc_String('4', 47, 8, str);
                    }

                    if (key_left) // 左移
                    {
                        Display_Asc_String('2', cursor_position, 22, " ");
                        if (num_cal_tmp.xb > 0)
                            num_cal_tmp.xb--;
                        else
                            num_cal_tmp.xb = 7;
                        if (num_cal_tmp.xb == 20)
                            num_cal_tmp.xb = num_cal_tmp.xb - 14;
                        if (num_cal_tmp.xb == 3)
                            num_cal_tmp.xb--;
                        if (num_cal_tmp.xb == 7)
                        {
                            num_cal_tmp.xb = num_cal_tmp.xb + 14;
                        }
                        cursor_position = 47 + num_cal_tmp.xb * 8;
                        Display_Asc_String('2', cursor_position, 22, "-");
                        //						sprintf((char *)str,"%d%d%d.%d%d%d",
                        //						num_cal_tmp.tmp_bit[0],
                        //						num_cal_tmp.tmp_bit[1],
                        //						num_cal_tmp.tmp_bit[2],
                        //						num_cal_tmp.tmp_bit[4],
                        //						num_cal_tmp.tmp_bit[5],
                        //						num_cal_tmp.tmp_bit[6]);
                        //						Display_Asc_String('4',47,8 ,str);
                    }

                    if (num_cal_tmp.xb == 21) //倒谱
                    {
                        sprintf((char *)str, "%s", cepstrum[cep]);
                        Display_Asc_String('4', 214, 8, str);
                        if (key_up) //上移按键
                        {
                            Display_Asc_String('4', 228, 8, "   ");
                            if (cep < 1)
                                cep++;
                            else
                                cep = 0;
                        }

                        if (key_down) // 下移按键
                        {
                            Display_Asc_String('4', 228, 8, "   ");
                            if (cep > 0)
                                cep--;
                            else
                                cep = 1;
                        }
                    }

                    if (key_up) //加
                    {
                        if (num_cal_tmp.tmp_bit[num_cal_tmp.xb] < 9)
                            num_cal_tmp.tmp_bit[num_cal_tmp.xb]++;
                        else
                            num_cal_tmp.tmp_bit[num_cal_tmp.xb] = 0;
                        sprintf((char *)str, "%d%d%d.%d%d%d",
                                num_cal_tmp.tmp_bit[0],
                                num_cal_tmp.tmp_bit[1],
                                num_cal_tmp.tmp_bit[2],
                                num_cal_tmp.tmp_bit[4],
                                num_cal_tmp.tmp_bit[5],
                                num_cal_tmp.tmp_bit[6]);
                        Display_Asc_String('4', 47, 8, str);
                    }

                    if (key_down) // 减
                    {
                        if (num_cal_tmp.tmp_bit[num_cal_tmp.xb] > 0)
                            num_cal_tmp.tmp_bit[num_cal_tmp.xb]--;
                        else
                            num_cal_tmp.tmp_bit[num_cal_tmp.xb] = 9;
                        sprintf((char *)str, "%d%d%d.%d%d%d",
                                num_cal_tmp.tmp_bit[0],
                                num_cal_tmp.tmp_bit[1],
                                num_cal_tmp.tmp_bit[2],
                                num_cal_tmp.tmp_bit[4],
                                num_cal_tmp.tmp_bit[5],
                                num_cal_tmp.tmp_bit[6]);
                        Display_Asc_String('4', 47, 8, str);
                    }
                    if (key_back)
                    {
                        num_cal_tmp.num_temp = (num_cal_tmp.tmp_bit[0] * 100000 +
                                                num_cal_tmp.tmp_bit[1] * 10000 +
                                                num_cal_tmp.tmp_bit[2] * 1000 +
                                                num_cal_tmp.tmp_bit[4] * 100 +
                                                num_cal_tmp.tmp_bit[5] * 10 +
                                                num_cal_tmp.tmp_bit[6] * 1) *
                                               1000; ///乘以1000，是因为num_cal_tmp.num_temp除以了1000；
                        Fill_RAM(0x00);              //清屏
                        pDevicepara->carrierfrequency = num_cal_tmp.num_temp;
                        pDevicepara->carrierfrequencycw = get_Carrier_frequency_control_word(pDevicepara->carrierfrequency);
                        SPI2_transfer64bit(Demodulation_parameters | Carrier_frequency_control_word | pDevicepara->carrierfrequencycw);
                        break;
                    }
                }
            }
            break;

        case 2:
            ///////////////////////////////FRAME///////////////////////////////////
            Display_Asc_String('4', 8, 8, "IF FRAME MODE DATA DEC MONITER");
            Display_Asc_String('4', 8, 20, "   -         ");
            /////////////////////////////////////////////////////////

            if (key_enter)
            {
                Fill_RAM(0x00);
                while (1)
                {
					Display_Asc_String('4', 6, 12, "FRAME");
                    Display_Asc_String('4', 46, 8, ":");
                    Display_Asc_String('2', 6, 48, "-");
                    sprintf((char *)str, "%s", Frame_Structure[frame]);
                    Display_Asc_String('4', 6, 34, str);
		 			Draw_Rectangle(0xff, 2, 60,254, 0, 62); //画灰度值 0xff（88，2）~（164，61）线宽为3像素的方框
					Display_Asc_String('4', 68, 12, "COM,EDMAC,EDMAC2,ESC++");
                    Display_Asc_String('4', 68, 36, "IBS,DROP,IDR,DVB,D&I++");

                //    Display_Asc_String('4', 80, 8, "FRAME");
                //    Display_Asc_String('4', 121, 4, ":");
                //    Display_Asc_String('2', 130, 22, "-");
                //    sprintf((char *)str, "%s", Frame_Structure[frame]);
                //    Display_Asc_String('4', 130, 8, str);
                //    Display_Asc_String('4', 0, 32, "IBS,DROP,IDR,EDMAC,DVB,ESC++,COM");
					

                    if (key_up)
                    {
                        Display_Asc_String('4', 6, 34, "      ");
                        if (frame < 8)
                        {
                            frame++;
                        }
                        else
                            frame = 0;
                    }

                    if (key_down)
                    {
                        Display_Asc_String('4', 6, 34, "      ");
                        if (frame > 0)
                        {
                            frame--;
                        }
                        else
                            frame = 8;
                    }

                    if (key_back)
                    {
                        Fill_RAM(0x00); //清屏
                        break;
                    } // 返回按键
                }
            }
            break;

        case 3:
            //////////////////////////////////MODE//////////////////////////////////////
            Display_Asc_String('4', 8, 8, "IF FRAME MODE DATA DEC MONITER");
            Display_Asc_String('4', 8, 20, "         -                    ");
            ///////////////////////////////////////////////////////////////////////////
            if (key_enter)
            {
                Fill_RAM(0x00);
                while (1)
                {
                    Display_Asc_String('4', 50, 8, "DEMODULATION");
                    Display_Asc_String('4', 151, 4, ":");
                    Display_Asc_String('2', 160, 22, "-");
                    sprintf((char *)str, "%s", Modulation_Mode[modul]);
                    Display_Asc_String('4', 160, 8, str);
                    Display_Asc_String('4', 0, 32, "BPSK,QPSK,OQPSK,8PSK,8QAM,16QAM");

                    if (key_up)
                    {

                        Display_Asc_String('4', 130, 8, "         ");
                        if (modul < 5)
                            modul++;
                        else
                            modul = 0;
                    }
                    if (key_down)
                    {
                        if (modul > 0)
                            modul--;
                        else
                            modul = 5;

                        Display_Asc_String('4', 130, 8, "         ");
                    }

                    if (key_back)
                    {
						modul1 = Modulation_Mode1[modul];
						pDevicepara->modulationsystem = 0;
						SPI2_transfer64bit(Demodulation_parameters | Modulation_system | pDevicepara->modulationsystem);
                        Fill_RAM(0x00);
                        break;
                    }
                }
            }
            break;

        case 4:
            /////////////////////////////////DATA//////////////////////////////////////
            Display_Asc_String('4', 8, 8, "IF FRAME MODE DATA DEC MONITER");
            Display_Asc_String('4', 8, 20, "              -            ");
            if (key_enter)
            {
                Fill_RAM(0x00);
				if(frame <=2)
				{
					while (1)
					{
						Display_Asc_String('4', 50, 8, "DATA");
						Display_Asc_String('4', 50, 36, "SYMBOL");
						Display_Asc_String('4', 82, 4, ":");
						Display_Asc_String('4', 98, 32, ":");
						Display_Asc_String('4', 164, 8, "Kbps");
						Display_Asc_String('4', 180, 36, "KBd");
						Display_Asc_String('2', 122, 22, "-");
						if(frame == 0)                                      //IBS
						{							
							num_cal_sign.num_temp = atof(IBS[IB])*1000/ cde1 / modul1 / demo1/15*16;
							sprintf((char *)str, "%s", IBS[IB]); 
							Display_Asc_String('4', 90, 8, str);
							if (key_up)
							{
								Display_Asc_String('4', 136, 8, "          ");
								if (IB < 32)
								{
									IB++;
								}
								else
									IB = 0;
							}

							if (key_down)
							{
								Display_Asc_String('4', 136, 8, "          ");
								if (IB > 0)
								{
									IB--;
								}
								else
									IB = 32;
							}
						}
						
						if(frame == 1)                    //DROP                                                       
						{							
							num_cal_sign.num_temp = atof(IBS[IB])*1000/ cde1 / modul1 / demo1/965*1024;
							sprintf((char *)str, "%s", IBS[IB]); 
							Display_Asc_String('4', 90, 8, str);
						if (key_up)
						{
							Display_Asc_String('4', 136, 8, "          ");
							if (IB < 32)
							{
								IB++;
							}
							else
								IB = 0;
						}

						if (key_down)
						{
							Display_Asc_String('4', 136, 8, "          ");
							if (IB > 0)
							{
								IB--;
							}
							else
								IB = 32;
						}
						}						

						if(frame == 2)                                     //IDR
						{
						num_cal_sign.num_temp = atof(IDR[idr])*1000/ cde1 / modul1 / demo1;							
						sprintf((char *)str, "%s", IDR[idr]);
						Display_Asc_String('4', 90, 8, str);

						if (key_up)
						{
							Display_Asc_String('4', 136, 8, "          ");
							if (idr < 3)
							{
								idr++;
							}
							else
								idr = 0;
						}

						if (key_down)
						{
							Display_Asc_String('4', 136, 8, "          ");
							if (idr > 0)
							{
								idr--;
							}
							else
								idr = 3;
						}
							
						}
						num_cal_sign.tmp_bit[8] = num_cal_sign.num_temp % 10; // 符号率
						num_cal_sign.tmp_bit[7] = (num_cal_sign.num_temp % 100) / 10;
						num_cal_sign.tmp_bit[6] = (num_cal_sign.num_temp % 1000) / 100;
						num_cal_sign.tmp_bit[4] = (num_cal_sign.num_temp % 10000) / 1000;
						num_cal_sign.tmp_bit[3] = (num_cal_sign.num_temp % 100000) / 10000;
						num_cal_sign.tmp_bit[2] = (num_cal_sign.num_temp % 1000000) / 100000;
						num_cal_sign.tmp_bit[1] = (num_cal_sign.num_temp % 10000000) / 1000000;
						num_cal_sign.tmp_bit[0] = (num_cal_sign.num_temp % 100000000) / 10000000;
						
						sprintf((char *)str, "%d%d%d%d%d.%d%d%d", //显示符号率
                        num_cal_sign.tmp_bit[0],
                        num_cal_sign.tmp_bit[1],
                        num_cal_sign.tmp_bit[2],
                        num_cal_sign.tmp_bit[3],
                        num_cal_sign.tmp_bit[4],
                        num_cal_sign.tmp_bit[6],
                        num_cal_sign.tmp_bit[7],
                        num_cal_sign.tmp_bit[8]);
						Display_Asc_String('4', 104, 36, str);
						
						if (key_back)
						{
							Fill_RAM(0x00); //清屏
							break;
						} 
					}
				}
				

 
				if(frame > 2 )
				{
                /////////////////将数值每一个位储存在数组的每一位里////////////////
                num_cal_information.tmp_bit[8] = num_cal_information.num_temp % 10 / 1; // 信息速率
                num_cal_information.tmp_bit[7] = (num_cal_information.num_temp % 100) / 10;
                num_cal_information.tmp_bit[6] = (num_cal_information.num_temp % 1000) / 100;
                num_cal_information.tmp_bit[4] = (num_cal_information.num_temp % 10000) / 1000;
                num_cal_information.tmp_bit[3] = (num_cal_information.num_temp % 100000) / 10000;
                num_cal_information.tmp_bit[2] = (num_cal_information.num_temp % 1000000) / 100000;
                num_cal_information.tmp_bit[1] = (num_cal_information.num_temp % 10000000) / 1000000;
                num_cal_information.tmp_bit[0] = (num_cal_information.num_temp % 100000000) / 10000000;

                num_cal_sign.tmp_bit[8] = num_cal_sign.num_temp % 10; // 符号率
                num_cal_sign.tmp_bit[7] = (num_cal_sign.num_temp % 100) / 10;
                num_cal_sign.tmp_bit[6] = (num_cal_sign.num_temp % 1000) / 100;
                num_cal_sign.tmp_bit[4] = (num_cal_sign.num_temp % 10000) / 1000;
                num_cal_sign.tmp_bit[3] = (num_cal_sign.num_temp % 100000) / 10000;
                num_cal_sign.tmp_bit[2] = (num_cal_sign.num_temp % 1000000) / 100000;
                num_cal_sign.tmp_bit[1] = (num_cal_sign.num_temp % 10000000) / 1000000;
                num_cal_sign.tmp_bit[0] = (num_cal_sign.num_temp % 100000000) / 10000000;

                Display_Asc_String('4', 50, 8, "DATA");
                Display_Asc_String('4', 50, 36, "SYMBOL");
                Display_Asc_String('4', 82, 4, ":");
                Display_Asc_String('4', 98, 32, ":");
                Display_Asc_String('4', 164, 8, "Kbps");
                Display_Asc_String('4', 180, 36, "KBd");
                cursor_position = 90 + num_cal_information.xb * 8;
                Display_Asc_String('2', cursor_position, 22, "-");

                sprintf((char *)str, "%d%d%d%d%d.%d%d%d", // 显示信息速率
                        num_cal_information.tmp_bit[0],
                        num_cal_information.tmp_bit[1],
                        num_cal_information.tmp_bit[2],
                        num_cal_information.tmp_bit[3],
                        num_cal_information.tmp_bit[4],
                        num_cal_information.tmp_bit[6],
                        num_cal_information.tmp_bit[7],
                        num_cal_information.tmp_bit[8]);
                Display_Asc_String('4', 90, 8, str);

                sprintf((char *)str, "%d%d%d%d%d.%d%d%d", //显示符号率
                        num_cal_sign.tmp_bit[0],
                        num_cal_sign.tmp_bit[1],
                        num_cal_sign.tmp_bit[2],
                        num_cal_sign.tmp_bit[3],
                        num_cal_sign.tmp_bit[4],
                        num_cal_sign.tmp_bit[6],
                        num_cal_sign.tmp_bit[7],
                        num_cal_sign.tmp_bit[8]);
                Display_Asc_String('4', 104, 36, str);
                //////////////////////////
				   while (1)
					{
						if (key_right) //右
						{
							Display_Asc_String('2', cursor_position, 22, " ");
							num_cal_information.xb++;
							if (num_cal_information.xb > 8)
								num_cal_information.xb = 0;
							if (num_cal_information.xb == 5)
								num_cal_information.xb++;
							cursor_position = 90 + num_cal_information.xb * 8;
							Display_Asc_String('2', cursor_position, 22, "-");
							sprintf((char *)str, "%d%d%d%d%d.%d%d%d",
									num_cal_information.tmp_bit[0],
									num_cal_information.tmp_bit[1],
									num_cal_information.tmp_bit[2],
									num_cal_information.tmp_bit[3],
									num_cal_information.tmp_bit[4],
									num_cal_information.tmp_bit[6],
									num_cal_information.tmp_bit[7],
									num_cal_information.tmp_bit[8]);
							Display_Asc_String('4', 90, 8, str);
						}

						if (key_left) //左
						{
							Display_Asc_String('2', cursor_position, 22, " ");
                            num_cal_information.xb--;
							if (num_cal_information.xb < 0)
								num_cal_information.xb = 8;
                            if (num_cal_information.xb == 5)
								num_cal_information.xb = 4;
							cursor_position = 90 + num_cal_information.xb * 8;
							Display_Asc_String('2', cursor_position, 22, "-");
							sprintf((char *)str, "%d%d%d%d%d.%d%d%d",
									num_cal_information.tmp_bit[0],
									num_cal_information.tmp_bit[1],
									num_cal_information.tmp_bit[2],
									num_cal_information.tmp_bit[3],
									num_cal_information.tmp_bit[4],
									num_cal_information.tmp_bit[6],
									num_cal_information.tmp_bit[7],
									num_cal_information.tmp_bit[8]);
							Display_Asc_String('4', 90, 8, str);
						}

						if (key_up) //加
						{
							if (num_cal_information.tmp_bit[num_cal_information.xb] < 9)
								num_cal_information.tmp_bit[num_cal_information.xb]++;
							else
								num_cal_information.tmp_bit[num_cal_information.xb] = 0;
							sprintf((char *)str, "%d%d%d%d%d.%d%d%d",
									num_cal_information.tmp_bit[0],
									num_cal_information.tmp_bit[1],
									num_cal_information.tmp_bit[2],
									num_cal_information.tmp_bit[3],
									num_cal_information.tmp_bit[4],
									num_cal_information.tmp_bit[6],
									num_cal_information.tmp_bit[7],
									num_cal_information.tmp_bit[8]);
							Display_Asc_String('4', 90, 8, str);
						}

						if (key_down) // 减
						{
							if (num_cal_information.tmp_bit[num_cal_information.xb] > 0)
								num_cal_information.tmp_bit[num_cal_information.xb]--;
							else
								num_cal_information.tmp_bit[num_cal_information.xb] = 9;
							sprintf((char *)str, "%d%d%d%d%d.%d%d%d",
									num_cal_information.tmp_bit[0],
									num_cal_information.tmp_bit[1],
									num_cal_information.tmp_bit[2],
									num_cal_information.tmp_bit[3],
									num_cal_information.tmp_bit[4],
									num_cal_information.tmp_bit[6],
									num_cal_information.tmp_bit[7],
									num_cal_information.tmp_bit[8]);
							Display_Asc_String('4', 90, 8, str);
						}
						/////////符号率同步关联，以下步骤不可缺
						//◤{*************************************************************◥
						num_cal_information.num_temp =
							num_cal_information.tmp_bit[0] * 10000000 +
							num_cal_information.tmp_bit[1] * 1000000 +
							num_cal_information.tmp_bit[2] * 100000 +
							num_cal_information.tmp_bit[3] * 10000 +
							num_cal_information.tmp_bit[4] * 1000 +
							num_cal_information.tmp_bit[6] * 100 +
							num_cal_information.tmp_bit[7] * 10 +
							num_cal_information.tmp_bit[8];
						if(frame == 3)
							num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/FRAMERATE_EDMAC(num_cal_information.num_temp,cde,modul);
						if(frame == 4||frame == 8)
							num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/demo1; 
						if(frame == 5)
							num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/FRAMERATE_ESC(num_cal_information.num_temp); //关联式
						if(frame == 6)
							num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/60*61; 
						if(frame == 7)
							num_cal_sign.num_temp = num_cal_information.num_temp/cde1/modul1/45*46; 
						
						num_cal_sign.tmp_bit[8] = num_cal_sign.num_temp % 10; // 符号率数值取位到数组
						num_cal_sign.tmp_bit[7] = (num_cal_sign.num_temp % 100) / 10;
						num_cal_sign.tmp_bit[6] = (num_cal_sign.num_temp % 1000) / 100;
						num_cal_sign.tmp_bit[4] = (num_cal_sign.num_temp % 10000) / 1000;
						num_cal_sign.tmp_bit[3] = (num_cal_sign.num_temp % 100000) / 10000;
						num_cal_sign.tmp_bit[2] = (num_cal_sign.num_temp % 1000000) / 100000;
						num_cal_sign.tmp_bit[1] = (num_cal_sign.num_temp % 10000000) / 1000000;
						num_cal_sign.tmp_bit[0] = (num_cal_sign.num_temp % 100000000) / 10000000;

						sprintf((char *)str, "%d%d%d%d%d.%d%d%d", //显示符号率
								num_cal_sign.tmp_bit[0],
								num_cal_sign.tmp_bit[1],
								num_cal_sign.tmp_bit[2],
								num_cal_sign.tmp_bit[3],
								num_cal_sign.tmp_bit[4],
								num_cal_sign.tmp_bit[6],
								num_cal_sign.tmp_bit[7],
								num_cal_sign.tmp_bit[8]);
						Display_Asc_String('4', 104, 36, str);
						//◣ *************************************************************}◢

						if (key_back)
						{
							num_cal_information.num_temp =
								num_cal_information.tmp_bit[0] * 10000000 +
								num_cal_information.tmp_bit[1] * 1000000 +
								num_cal_information.tmp_bit[2] * 100000 +
								num_cal_information.tmp_bit[3] * 10000 +
								num_cal_information.tmp_bit[4] * 1000 +
								num_cal_information.tmp_bit[6] * 100 +
								num_cal_information.tmp_bit[7] * 10 +
								num_cal_information.tmp_bit[8];
							Fill_RAM(0x00);
							break;
						}
					}
				}
            }
            break;

            ////////////////////////////////////DEC///////////////////////////////////////
        case 5:
            Display_Asc_String('4', 8, 8, "IF FRAME MODE DATA DEC MONITER");
            Display_Asc_String('4', 8, 20, "                   -          ");
            if (key_enter)
            {
                Fill_RAM(0x00);
                Display_Asc_String('4', 8, 20, "                              ");

                while (1)
                {
                    Display_Asc_String('4', 4, 8, "DEC");
                    Display_Asc_String('4', 30, 4, ":");
                    sprintf((char *)str, "%s", Decoded_Mode[decmo]);
                    Display_Asc_String('4', 38, 8, str);

                    Display_Asc_String('4', 88, 8, "RATE");
                    Display_Asc_String('4', 120, 4, ":");
                    sprintf((char *)str, "%s", code[cde]);
                    Display_Asc_String('4', 128, 8, str);

                    Display_Asc_String('4', 176, 8, "DES");
                    Display_Asc_String('4', 202, 4, ":");
                    sprintf((char *)str, "%s", Scramble[scram]);
                    Display_Asc_String('4', 208, 8, str);

                    Display_Asc_String('4', 4, 36, "R-S");
                    Display_Asc_String('4', 30, 32, ":");
                    sprintf((char *)str, "%s", RS_Decoding_Mode[demo]);
                    Display_Asc_String('4', 38, 36, str);

                    Display_Asc_String('4', 124, 36, "INT-LEA");
                    Display_Asc_String('4', 182, 32, ":");
                    sprintf((char *)str, "%s", RS_Interweave_Depth[itwdp]);
                    Display_Asc_String('4', 188, 36, str);
                    if (key_right)
                    {
                        if (j < 5)
                            j++;
                        else
                            j = 1;
                    }
                    if (key_left)
                    {

                        if (j > 1)
                            j--;
                        else
                            j = 5;
                    }
                    //						j =	Num_Range(1,5);

                    switch (j)
                    {
                    case 1:
                        Display_Asc_String('4', 188, 48, " ");
                        Display_Asc_String('4', 128, 20, " ");
                        if (key_up)
                        {
                            Display_Asc_String('4', 38, 8, "    ");
                            if (decmo < 5)
                                decmo++;
                            else
                                decmo = 0;
                        }
                        if (key_down)
                        {
                            Display_Asc_String('4', 38, 8, "    ");
                            if (decmo > 0)
                                decmo--;
                            else
                                decmo = 5;
                        }
                        Display_Asc_String('4', 38, 20, "-");
                        sprintf((char *)str, "%s", Decoded_Mode[decmo]);
                        Display_Asc_String('4', 38, 8, str);

                        break;

                    case 2:
                        Display_Asc_String('4', 208, 20, " ");
                        Display_Asc_String('4', 38, 20, " ");
                        if (key_up)
                        {
                            Display_Asc_String('4', 128, 8, "     ");
                            if (cde < 11)
                                cde++;
                            else
                                cde = 0;
						cde1 = code1[cde];
                        }
                        if (key_down)
                        {
                            Display_Asc_String('4', 128, 8, "     ");
                            if (cde > 0)
                                cde--;
                            else
                                cde = 11;
						cde1 = code1[cde];
                        }
                        Display_Asc_String('4', 128, 20, "-");
                        sprintf((char *)str, "%s", code[cde]);
                        Display_Asc_String('4', 128, 8, str);
                        break;

                    case 3:
                        Display_Asc_String('4', 38, 52, " ");
                        Display_Asc_String('4', 128, 20, " ");
                        if (key_up)
                        {
                            Display_Asc_String('4', 208, 8, "       ");
                            if (scram < 4)
                                scram++;
                            else
                                scram = 0;
                        }
                        if (key_down)
                        {
                            Display_Asc_String('4', 208, 8, "       ");
                            if (scram > 0)
                                scram--;
                            else
                                scram = 4;
                        }
                        Display_Asc_String('4', 208, 20, "-");
                        sprintf((char *)str, "%s", Scramble[scram]);
                        Display_Asc_String('4', 208, 8, str);
                        break;

                    case 4:
                        Display_Asc_String('4', 188, 48, " ");
                        Display_Asc_String('4', 208, 20, " ");
                        if (key_up)
                        {
                            Display_Asc_String('4', 38, 36, "         ");
                            if (demo < 6)
                                demo++;
                            else
                                demo = 0;
						demo1 = RS_Decoding_Mode1[demo];
                        }
                        if (key_down)
                        {
                            Display_Asc_String('4', 38, 36, "         ");
                            if (demo > 0)
                                demo--;
                            else
                                demo = 6;
						demo1 = RS_Decoding_Mode1[demo];
                        }
                        Display_Asc_String('4', 38, 50, "-");
                        sprintf((char *)str, "%s", RS_Decoding_Mode[demo]);
                        Display_Asc_String('4', 38, 36, str);
                        break;

                    case 5:
                        Display_Asc_String('4', 38, 20, " ");
                        Display_Asc_String('4', 38, 52, " ");
                        if (key_up)
                        {
                            Display_Asc_String('4', 188, 36, "    ");
                            if (itwdp < 3)
                                itwdp++;
                            else
                                itwdp = 0;
                        }
                        if (key_down)
                        {
                            Display_Asc_String('4', 188, 36, "    ");
                            if (itwdp > 0)
                                itwdp--;
                            else
                                itwdp = 3;
                        }
                        Display_Asc_String('4', 188, 48, "-");
                        sprintf((char *)str, "%s", RS_Interweave_Depth[itwdp]);
                        Display_Asc_String('4', 188, 36, str);
                        break;
                    }
                    if (key_back)
                    {
                        Fill_RAM(0x00);
                        break;
                    }
                }
            }

            break;

            ////////////////////////////////////MONITER///////////////////////////////////////
        case 6:
            Display_Asc_String('4', 8, 8, "IF FRAME MODE DATA DEC MONITER");
            Display_Asc_String('4', 8, 20, "                       -      ");
            break;
        default:
            break;
        }
    }
}
